package com.think.common.model;

import java.util.ArrayList;
import java.util.List;

public enum ResultCode {
	/* 成功状态码 */
	SUCCESS(10000, "成功"),

	/* 参数错误：10001-19999 */
	PARAM_IS_INVALID(10001, "参数无效"),
	PARAM_IS_BLANK(10002, "参数为空"),
	PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
	PARAM_NOT_COMPLETE(10004, "参数缺失"),
	PARAM_TOKEN_MISS(10005,"缺少Token"),
	PARAM_TOKEN_EXPIRED(10006,"登陆已过期，请重新登陆！"),
	USER_NAME_PASSWORD_INVALID(10007,"用户名或者密码错误！"),
	TOKEN_IS_INVALID(10008,"Token校验错误！"),

	/* 用户错误：20001-29999*/
	USER_NOT_LOGGED_IN(20001, "用户未登录"),
	USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
	USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
	USER_NOT_EXIST(20004, "用户不存在"),
	PROJECT_NOT_EXIST(20005, "项目不存在"),
	USER_INFO_NOT_FOUND(20006,"用户信息不存在"),
	USER_NOT_INIT(20007,"用户信息没有初始化"),
	USER_HAS_EXISTED(20008, "用户已存在"),
	GROUP_NOT_EXIST(20009, "部门不存在"),
	GROUP_HAS_EXIST(20010, "部门已存在"),
	GROUP_NOT_EMPTY(20011,"部门人员没有清空"),
	GROUP_STRUCT_LOOP(20012,"部门数据结构循环"),
	ILAB_LOGIN_NOT_MATCH(20013,"实验空间登录和项目不匹配"),
	
	/* 业务错误：30001-39999 */
	QUESTION_NOT_EXIST(30001,"试题不存在"),
	QUESTION_ANSWER_NOT_EXIST(30002,"试题参考答案不存在"),
	QUESTION_SELECTION_NOT_EXIST(30003,"试题选项不存在"),
	QUESTION_TAG_NOT_EXIST(30004,"试题标签不存在"),
	QUESTION_TYPE_NOT_EXIST(30005,"试题类型不存在"),
	QUESTION_TYPE_ALREADY_EXIST(30006,"试题类型已存在"),
	QUESTION_TYPE_NOT_MATCH(30007,"试题类型错误"),
	
	EXAM_PAPER_NOT_EXIST(30010,"试卷不存在"),
	EXAM_RESULT_NOT_EXIST(30011,"学生答题答案不存在"),
	EXAM_TEST_NOT_EXIST(30012,"考试不存在"),
	USER_EXAM_RESULT_NOT_EXIST(30013,"用户考试记录不存在"),
	USER_EXAM_RESULT_ALREADY_EXIST(30014,"用户考试记录已存在"),
	USER_EXAM_RESULT_ALREADY_CORRECTED(30015,"用户考试已批改"),

	PAPER_QUESTION_NOT_EXIST(30021,"试卷试题不存在"),
	PAPER_TAG_NOT_EXIST(30022,"试卷标签不存在"),
	PAPER_ZONE_NOT_EXIST(30023,"试卷分区不存在"),
	EXAM_PAPER_TYPE_NOT_EXIST(30024,"试卷类型不存在"),
	EXAM_PAPER_TYPE_ALREADY_EXIST(30025,"试卷类型已存在"),
	PAPER_QUESTION_ALREADY_EXIST(30021,"试卷试题已存在"),
	
	TRAINING_NOT_EXIST(30031,"实训不存在"),
	TRAINING_CHECK_POINT_NOT_EXIST(30032,"实训计分点不存在"),
	TRAINING_RESULT_NOT_EXIST(30032,"实训结果不存在"),
	TRAINING_TAG_NOT_EXIST(30033,"实训标签不存在"),
	TRAINING_TEST_NOT_EXIST(30034,"实训测试不存在"),
	EXAM_TEST_TIME_ERROR(30035,"当前时间不是考试时间"),
	
	STUDENT_NOT_EXIST(30101,"学生信息不存在"),
	STUDENT_ALREADY_EXIST(30102,"学生信息已经存在"),
	TEACHER_NOT_EXIST(30103,"老师信息不存在"),
	TEACHER_ALREADY_EXIST(30104,"老师信息已经存在"),
	
	CLASS_NOT_EXIST(30105,"班级不存在"),
	COLLEGE_NOT_EXIST(30106,"院系不存在"),
	GRADE_NOT_EXIST(30107,"年級不存在"),
	MAJOR_NOT_EXIST(30108,"专业不存在"),
	SCHOOL_NAME_DUL(30109,"学校名称已经存在"),
	SCHOOL_NOT_EXIST(30110,"学校不存在"),
	DURING_REVIEW(30111,"正在审核中"),
	
	
	/* 系统错误：40001-49999 */
	SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
	SYSTEM_DATABASE_ERROR(40002, "数据库错误"),

	/* 数据错误：50001-599999 */
	RESULT_DATA_NONE(50001, "数据未找到"),
	DATA_IS_WRONG(50002, "资源类型不符合要求"),
	DATA_ALREADY_EXISTED(50003, "数据已存在"),
	NEWS_NOT_EXIST(50013,"新闻不存在"),
	NEWS_TYPE_NOT_EXIST(50014,"新闻类型不存在"),
	NEWS_TIME_NOT_EXIST(50015,"新闻时间限制不存在"),
	NEWS_STORED_NOT_EXIST(50016,"新闻收藏不存在"),
	USER_ACTION_NOT_EXIST(50017,"用户行为信息不存在"),
	NEWS_LIMIT_NOT_EXIST(50018,"新闻权限不存在"),
	

	
	QRCODE_EXP(50024,"二维码过期"),
	QRCODE_WAIT(50025,"等待扫码"),
	
	AUDIO_NOT_EXIST(50026,"歌曲不存在"),
	/* 接口错误：60001-69999 */
	INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
	INTERFACE_OUTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
	INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
	INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
	INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
	INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),

	/* 权限错误：70001-79999 */
	PERMISSION_NO_ACCESS(70001, "无访问权限"),
	
	/* 课程相关： 80001-80021*/
	IMAGE_UPLOAD_ERROR(80001, "图片上传错误"),
	DOC_UPLOAD_ERROR(80002, "文档上传错误"),
	ASSET_TYPE_NOT_DEFINE(80003,"未定义的资源类型"),
	ASSET_NOT_EXITS(80004,"资源不存在"),
	
	ARTICLE_NOT_EXIST(80105,"文章不存在"),
	ARTICLE_LESSON_NOT_EXIST(80106,"文章课程不存在"),
	ARTICLE_TYPE_NOT_DEFINE(80107,"未定义的资源类型"),
	ARTICLE_TYPE_ALREADY_EXIST(80108,"文章类型已经存在"),
	ARTICLE_TITLE_ALREADY_EXIST(80109,"文章标题重复"),
	
	COURSE_NOT_EXIST(80007,"课程不存在"),
	COURSE_MODE_NOT_EXIST(80008,"课程形式不存在"),
	COURSE_TAG_NOT_EXIST(80009,"课程标签不存在"),
	COURSE_TYPE_NOT_EXIST(80010,"课程类型不存在"),
	COURSE_USER_NOT_EXIST(80011,"用户课程不存在"),
	
	
	LIVING_LESSON_COURSE_NOT_EXIST(80012,"直播课程不存在"),
	VIDEO_LESSON_COURSE_NOT_EXIST(80013,"视频互动课程不存在"),
	VR_LESSON_COURSE_NOT_EXIST(80014,"虚拟仿真课程不存在"),
	VR_LESSON_TEACHER_NOT_EXIST(80015,"虚拟仿真课程老师不存在"),
	
	COURSE_COMMENT_NOT_EXIST(80016,"课程评论不存在"),
	
	CHAPTER_NOT_EXIST(80017,"章不存在"),
	ASSET_TYPE_NOT_EXIST(80018,"资源类型不存在"),
	CHAPTER_ASSETS_NOT_EXIST(80019,"课件不存在"),
	COMPONENT_NOT_EXIST(80020,"视频课程组件不存在"),
	
	TAG_NOT_EXIST(80021,"标签不存在"),
	TAG_ALREADY_EXIST(80022,"标签已经存在"),
	TAG_TYPE_ERROR(80023,"标签类型错误"),

	ROOM_NOT_EXIST(80021,"实训室不存在"),
	ROOMRES_ALREADY_EXIST(80021,"你已预订该实训室！"),

	COURSE_TYPE_ALREADY_EXIST(80024,"课程类型已经存在"),
	LESSON_NOT_MATCH_CHAPTER(80025,"课程内容和章节配置不匹配"),
	CHAPTER_NO_LESSON(80026,"当前章节下不存在课程"),
	CHAPTER_ALREADY_LESSON(80027,"当前章节下已经存在课程"),
	COURSE_MODE_NOT_MATCH(80028,"课程形式不匹配"),
	COURSE_ALREADY_HAS_TEACHER(80029,"课程已经存在该老师信息"),
	CHAPTER_TYPE_ERROR(80030,"错误的章节类型"),
	COURSE_USER_EXIST(80031,"用户课程已经存在"),
	CHAPTER_MISSMATCH_COURSE(80032,"章节和课程不匹配"),
	COURSE_MEMBER_NOT_EXIST(80032,"课程成员不存在"),
	COURSE_COMMENT_NO_CONTENT(80034,"评论不能为空"),
	EXP_STAT_NOTEXITS(80036,"实验记录不存在或者实验未开始"),
	EXP_STAT_FINISHED(80037,"实验记录已经完成"),
	EXP_STAT_MISSING_START(80038,"实验记录缺少开始时间"),

	INTERFACE_UNIMPLEMENTED(9000,"接口未实现"),
	PARAM_FILE_EMPTY(9001, "文件名参数不存在"),
	FILE_ALREADY_EXITS(9002, "文件已经存在"),
	FILE_NOT_ZIP(9003,"文件不是zip文件"),
	FILE_TOO_BIG(9004,"文件太大"),
	
	//用户事件统计相关
	ACTIONTYPE_NOT_EXIST(100001,"事件类型不存在"),
	ACTIONTYPE_ALREADY_EXIST(100002,"事件类型已存在"),
	ACTIONDATA_NOT_EXIST(100011,"事件数据记录不存在"),
	ACTIONDATA_ALREADY_EXIST(100012,"事件数据记录已存在");
	
	
	
	private final Integer code;

	private final String message;

	ResultCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer code() {
		return this.code;
	}

	public String message() {
		return this.message;
	}

	public static String getMessage(String name) {
		for (ResultCode item : ResultCode.values()) {
			if (item.name().equals(name)) {
				return item.message;
			}
		}
		return name;
	}

	public static Integer getCode(String name) {
		for (ResultCode item : ResultCode.values()) {
			if (item.name().equals(name)) {
				return item.code;
			}
		}
		return null;
	}

	@Override
	public String toString() {
		return this.name();
	}

	//校验重复的code值
	public static void main(String[] args) {
		ResultCode[] ApiResultCodes = ResultCode.values();
		List<Integer> codeList = new ArrayList<Integer>();
		for (ResultCode ApiResultCode : ApiResultCodes) {
			if (codeList.contains(ApiResultCode.code)) {
				System.out.println(ApiResultCode.code);
			} else {
				codeList.add(ApiResultCode.code());
			}
		}
	}
}
